//
//  BaseTableViewController.swift
//  ZHTQWeibo
//
//  Created by ZHTQ on 2018/9/14.
//  Copyright © 2018年 ZHTQ. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {
    ///是否已经登录
    var isLogin: Bool = UserAccount.isLogin()
    
    ///view
    var visitorView: VisitorView?
    
    override func loadView() {
     isLogin ?  super.loadView() : setupView()
    }
    //MARK: - 内部控制方法
    private func setupView(){
        visitorView = VisitorView.visitorView()
        view = visitorView
        //开启首页动画
        visitorView?.startRotationImageViewAnimation()

        //监听注册 登录按钮的点击
        visitorView?.registerButtion.addTarget(self, action: #selector(registerButtonClick(button:)), for: UIControlEvents.touchUpInside)
        visitorView?.logionButton.addTarget(self, action: #selector(loginButtonClick(button:)), for: UIControlEvents.touchUpInside)
        
        //设置导航条左右按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.plain, target: self, action: #selector(registerButtonClick(button:)))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.plain, target: self, action: #selector(loginButtonClick(button:)))
    }
    
    
    @objc private func registerButtonClick(button: UIButton) {
        ZHLog("sdf")
    }
    
    @objc private func loginButtonClick(button: UIButton) {
        
        //弹出注册界面
        let sb = UIStoryboard(name: "Oauth", bundle: nil)
        guard let vc = sb.instantiateInitialViewController() else {
            return
        }
        
        present(vc, animated: true, completion: nil)
    }
    
}

